{% extends 'dashboard/layout.html' %}
{% load currency_filters %}
{% load i18n %}
{% load thumbnail %}

{% block body_class %}catalogue{% endblock %}

{% block title %}
{% trans "Product management" %} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
<ul class="breadcrumb">
    <li>
        <a href="{% url dashboard:index %}">{% trans "Dashboard" %}</a>
        <span class="divider">/</span>
    </li>
    <li class="active">{% trans "Product management" %}</li>
</ul>
{% endblock %}

{% block header %}
<div class="page-header action">
    <h1>{% trans "Product management" %}</h1>
</div>
{% endblock header %}

{% block dashboard_content %}
<div class="table-header">
    <h3><i class="icon-search icon-large"></i>{% trans "Search Products" %}</h3>
</div>
<div class="well">
    <form action="." method="get" class="form-inline">
        {% include "partials/form_fields_inline.html" with form=form %}
        <button type="submit" class="btn btn-primary">{% trans "Search" %}</button>
    </form>
</div>

<div class="table-header">
    <h3><i class="icon-sitemap icon-large"></i> {% trans "Create new product" %}</h3>
</div>
<div class="well">
    <form action="{% url dashboard:catalogue-product-create %}" method="get" class="form-inline">
        <span class="control-group">
            <label for="id_promotion_type">{% trans "Create a new product of type" %}</label>
            <select id="id_promotion_type" name="product_class">
                <option> -- {% trans "Choose type" %} --</option>
                {% for product_class in product_classes %}
                <option value="{{ product_class.id }}">{{ product_class.name }}</option>
                {% endfor %}
            </select>
        </span>
        <button class="btn btn-primary" type="submit"><i class="icon-plus"></i> {% trans "New Product" %}</button>
    </form>
</div>

{% if products %}
<div class="table-header">
    <h2><i class="icon-sitemap icon-large"></i>{{ queryset_description }}</h2>
</div>
<form action="." method="post">
    {% csrf_token %}
    <table class="table table-striped table-bordered">
        <tr>
            <th>{% trans "UPC" %}</th>
            <th>{% trans "Image" %}</th>
            <th>{% trans "Title" %}</th>
            <th>{% trans "Size" %}</th>
            <th>{% trans "Color" %}</th>
            <th>{% trans "Peso" %}</th>
            <th>{% trans "Product class" %}</th>
            <th>{% trans "Status" %}</th>
            <th>{% trans "Price excl. tax" %}</th>
            <th>{% trans "Price incl. tax" %}</th>
            <th>{% trans "Number in stock" %}</th>
            <th>{% trans "Number allocated" %}</th>
            <th>{% trans "Parent" %}</th>
            <th>{% trans "Children" %}</th>
            <th></th>
        </tr>
        {% for product in products %}
        <tr>
                <td>{{ product.upc|default:"-" }}</td>
                <td>
                {% if product.primary_image.original.url %}
                {% with image=product.primary_image %}
                    {% thumbnail image.original "70x70" upscale=False as thumb %}
                        <a href="{{ image.original.url }}" rel="lightbox_{{ product.upc|default:"-" }}" class="sub-image">
                            <img src="{{ thumb.url }}" alt="{{ product.get_title }}" data-description="{% if image.caption %}{{ image.caption }}{% endif %}">
                        </a>
                    {% endthumbnail %}
                {% endwith %}
                {% else %}
                -
                {% endif %}
                </td>
                <td>{{ product.get_title }}</td>
                <td>{{ product.size }}</td>
                <td>{{ product.color }}</td>
                <td>{{ product.peso }}</td>
                <td>{{ product.product_class.name }}</td>
                <td>{{ product.status|default:"-" }}</td>
                {% with stockrecord=product.stockrecord %}
                    <td>{{ stockrecord.price_excl_tax|currency }}</td>
                    <td>{{ stockrecord.price_incl_tax|currency }}</td>
                    <td>{{ stockrecord.num_in_stock|default:"-" }}</td>
                    <td>{{ stockrecord.num_allocated }}</td>
                {% endwith %}
                <td>
                    {% if product.parent.id %}
                    <a href="{% url dashboard:catalogue-product product.parent.id %}">{{ product.parent.title }}</a>
                    {% else %}
                    -
                    {% endif %}
                </td>
                <td>{{ product.variants.count }}</td>
                <td>
                    <div class="btn-toolbar">
                        <div class="btn-group">
                            <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                                {% trans "Actions" %}
                                <span class="caret"></span>
                            </a>
                            <ul class="dropdown-menu pull-right">
                                <li>
                                    <a href="{% url dashboard:catalogue-product product.id %}{% if request.GET.urlencode %}?{{ request.GET.urlencode }}{% endif %}">
                                        {% trans "Edit" %}
                                    </a>
                                </li>
                                <li>
                                    <a href="{{ product.get_absolute_url }}">
                                        {% trans "View on site" %}
                                    </a>
                                </li>
                                <li>
                                    <a href="{% url dashboard:catalogue-product-delete product.id %}">
                                        {% trans "Delete" %}
                                    </a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </td>
        </tr>
        {% endfor %}
    </table>
    {% include "partials/pagination.html" %}
</form>

{% else %}

<p>{% trans "No products found." %}</p>

{% endif %}

{% endblock dashboard_content %}
